package cc.lucien.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lucien-ma
 * @date 2021/10/29
 * @apiNote
 */
public class NewspaperOffice {

    private List<Customer> customers = new ArrayList<>();

    /**
     * 记录订阅者
     * @param customer
     */
    public void addCustomer(Customer customer) {
        customers.add(customer);
    }

    /**
     * 通知所有订阅者
     */
    public void notifyAllObservers() {
        for (Customer customer : customers) {
            customer.update();
        }
    }

    /**
     * 当有新报纸的时候给所有订阅者送达
     */
    public void newspaper() {
        this.notifyAllObservers();
    }
}
